package de.mhus.lib.mandala.impl;

import java.io.PrintWriter;

import de.mhus.lib.core.base.IgnoreBind;
import de.mhus.lib.mandala.Response;
import de.mhus.lib.mandala.Ui;
import de.mhus.lib.mandala.Window;
import de.mhus.lib.mandala.bind.RemoteRegistry;

@IgnoreBind
public class DefaultWindow extends Window implements SetUi, WindowExtended {

	@Override
	public void setUi(Ui ui) {
		this.ui = ui;
	}

	@Override
	public String getRemoteUrl(RemoteRegistry registry) {
		//TODO ...
		return getUi().getWebPath() + "callback?_mandala_action=" + getId() + "." + registry.getCallable().getId();
	}

	@Override
	public void beforeRemoteCall(Response out, String string) {
		if (getWindow().getUi().isDebugRemoteCalls())
			out.println("if (console) console.log('request: ' + "+string+");");
	}

	@Override
	public void afterRemoteCall(Response out, String string) {
		if (getUi().isDebugRemoteCalls())
			out.println("    if (console) console.log('response: ' + JSON.stringify("+string+"));");
	}

}
